local draft_rule = fk.CreateSkill{
  name = "#draft_rule",
}

Fk:loadTranslationTable{
  ["#draft_rule"] = "征召模式",

  ["#loyalist-wait"] = "内奸自立：很可惜，你不能参与",
  ["#renegade-standup"] = "内奸自立：三年之期已到！你可以亮出身份牌，加1点体力上限，回复1点体力，杀死主公将继续游戏！",
  ["#renegadeExploded"] = "内奸自立！%from 加了1点体力上限，回复了1点体力！",
}

draft_rule:addEffect(fk.Deathed, {
  mute = true,
  priority = 0,
  can_trigger = function (self, event, target, player, data)
    if target.role ~= "rebel" or not player.role:endsWith("renegade") then return end
    local room = player.room
    if #table.filter(room.alive_players, function (p) return p.role == "rebel" end) > 0 then return end
    return #table.filter(room.alive_players, function (p) return p.role:endsWith("renegade") end) == 1
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local req = Request:new(room.alive_players, "AskForSkillInvoke")
    req.receive_decode = false
    req.focus_text = "draft_rule"
    for _, p in ipairs(room.alive_players) do
      local prompt = "#loyalist-wait"
      if p == player then
        prompt = "#renegade-standup"
      end
      req:setData(p, { self.name, prompt })
    end

    local choice = req:getResult(player)
    if choice ~= "" then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:sendLog { type = "#renegadeExploded", from = player.id, toast = true }
    room:setPlayerProperty(player, "role_shown", true)
    room:setTag("renegade-standup", true)
    room:changeMaxHp(player, 1)
    room:recover{
      num = 1,
      who = player,
      recoverBy = player,
    }
  end
})

draft_rule:addEffect(fk.DrawInitialCards, {
  priority = 0,
  can_refresh = function(self, event, target, player, data)
    return target == player and player.seat > 5
  end,
  on_refresh = function(self, event, target, player, data)
    data.num = data.num + (player.seat - 4) // 2
  end,
})

return draft_rule